//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "CCheckMonnaie.h"
#include "CDevise.h"

#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck est utilisé est utilisé pour être sûr que les composants créés n'ont
// aucune fonction virtuelle pure.
//

static inline void ValidCtrCheck(CCheckMonnaie *)
{
  new CCheckMonnaie(NULL);
}
//---------------------------------------------------------------------------
__fastcall CCheckMonnaie::CCheckMonnaie(TComponent* Owner) : CComboBox(Owner)
{
  OnDrawItem = DrawItemMonnaie;
  Width = 81;
  Style = csOwnerDrawFixed;
  Visible = _CodePays == CP_FRANCE;
//      ItemIndex = 1;
//  Euro = false;
}
//---------------------------------------------------------------------------
namespace Ccheckmonnaie
{
  void __fastcall PACKAGE Register()
  {
     TComponentClass classes[1] = {__classid(CCheckMonnaie)};
     RegisterComponents("EIC Ctrlstd", classes, 0);
  }
}
//---------------------------------------------------------------------------
bool __fastcall CCheckMonnaie::GetEuro()
{
  return ItemIndex == 0;
}



void __fastcall CCheckMonnaie::SetEuro(bool euro)
{
  if (euro)
    ItemIndex = 0;
  else
    ItemIndex = 1;
}



void __fastcall CCheckMonnaie::SetParent(TWinControl* AParent)
{
  CComboBox::SetParent(AParent);
  if (AParent)
    {
//  Parent = (TWinControl *)Owner;
      Items->Clear();
      Items->Add("Euro");
      Items->Add("Franc");
      ItemIndex = 1;
//      Euro = true;
//      Euro = Euro;
    }
}



void __fastcall CCheckMonnaie::DrawItemMonnaie(TWinControl *Control,int Index,const TRect &Rect,TOwnerDrawState State)
{
  Graphics::TBitmap *Image;
  try
    {
      Canvas->FillRect(Rect);
      if (!Enabled)
        return;
      Image = new Graphics::TBitmap();
      Image->Height = 12;
      Image->Width = 16;
      Image->Transparent = true;
      Image->LoadFromResourceName((int)HInstance,Index ? "1DRA_FRF" : "1DRA_EUR");
      Canvas->Draw(Rect.Left + 2,Rect.Top + 1,Image);
      Canvas->TextOut(Rect.Left + Image->Width + 6,Rect.Top + 1,Items->Strings[Index]);
    }
  catch (...)
    {
    }
}



const CDevise& __fastcall CCheckMonnaie::GetDevise()
{
  if (Euro)
    return DeviseEuro;
  else
    return DeviseFranc;
}



